package org.htmlparser.tags;

import org.htmlparser.Node;
import org.htmlparser.lexer.Page;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.ParserUtils;
import org.htmlparser.util.SimpleNodeIterator;

public class LinkTag extends CompositeTag
{
  private static final String[] mEndTagEnders;
  private static final String[] mEnders;
  private static final String[] mIds;
  private boolean javascriptLink;
  protected String mLink;
  private boolean mailLink;

  static
  {
    String[] arrayOfString1 = new String[1];
    arrayOfString1[0] = "A";
    mIds = arrayOfString1;
    String[] arrayOfString2 = new String[7];
    arrayOfString2[0] = "A";
    arrayOfString2[1] = "P";
    arrayOfString2[2] = "DIV";
    arrayOfString2[3] = "TD";
    arrayOfString2[4] = "TR";
    arrayOfString2[5] = "FORM";
    arrayOfString2[6] = "LI";
    mEnders = arrayOfString2;
    String[] arrayOfString3 = new String[8];
    arrayOfString3[0] = "P";
    arrayOfString3[1] = "DIV";
    arrayOfString3[2] = "TD";
    arrayOfString3[3] = "TR";
    arrayOfString3[4] = "FORM";
    arrayOfString3[5] = "LI";
    arrayOfString3[6] = "BODY";
    arrayOfString3[7] = "HTML";
    mEndTagEnders = arrayOfString3;
  }

  public String extractLink()
  {
    String str = getAttribute("HREF");
    if (str != null)
      str = ParserUtils.removeChars(ParserUtils.removeChars(str, '\n'), '\r');
    if (getPage() != null)
      str = getPage().getAbsoluteURL(str);
    return str;
  }

  public String getAccessKey()
  {
    return getAttribute("ACCESSKEY");
  }

  public String[] getEndTagEnders()
  {
    return mEndTagEnders;
  }

  public String[] getEnders()
  {
    return mEnders;
  }

  public String[] getIds()
  {
    return mIds;
  }

  public String getLink()
  {
    if (this.mLink == null)
    {
      this.mailLink = false;
      this.javascriptLink = false;
      this.mLink = extractLink();
      if (this.mLink.indexOf("mailto") == 0)
      {
        int i = this.mLink.indexOf(":");
        this.mLink = this.mLink.substring(i + 1);
        this.mailLink = true;
      }
      if (this.mLink.indexOf("javascript:") == 0)
      {
        this.mLink = this.mLink.substring(11);
        this.javascriptLink = true;
      }
    }
    return this.mLink;
  }

  public String getLinkText()
  {
    String str;
    if (getChildren() != null)
      str = getChildren().asString();
    while (true)
    {
      return str;
      str = "";
    }
  }

  public boolean isFTPLink()
  {
    int i;
    if (getLink().indexOf("ftp://") == 0)
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public boolean isHTTPLikeLink()
  {
    int i;
    if ((isHTTPLink()) || (isHTTPSLink()))
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public boolean isHTTPLink()
  {
    int i;
    if ((!(isFTPLink())) && (!(isHTTPSLink())) && (!(isJavascriptLink())) && (!(isMailLink())) && (!(isIRCLink())))
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public boolean isHTTPSLink()
  {
    int i;
    if (getLink().indexOf("https://") == 0)
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public boolean isIRCLink()
  {
    int i;
    if (getLink().indexOf("irc://") == 0)
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public boolean isJavascriptLink()
  {
    getLink();
    return this.javascriptLink;
  }

  public boolean isMailLink()
  {
    getLink();
    return this.mailLink;
  }

  public void setJavascriptLink(boolean paramBoolean)
  {
    this.javascriptLink = paramBoolean;
  }

  public void setLink(String paramString)
  {
    this.mLink = paramString;
    setAttribute("HREF", paramString);
  }

  public void setMailLink(boolean paramBoolean)
  {
    this.mailLink = paramBoolean;
  }

  public String toString()
  {
    StringBuffer localStringBuffer1 = new StringBuffer();
    localStringBuffer1.append("Link to : " + getLink() + "; titled : " + getLinkText() + "; begins at : " + getStartPosition() + "; ends at : " + getEndPosition() + ", AccessKey=");
    if (getAccessKey() == null)
      localStringBuffer1.append("null\n");
    while (getChildren() != null)
    {
      int i = 0;
      SimpleNodeIterator localSimpleNodeIterator = children();
      while (true)
      {
        if (!(localSimpleNodeIterator.hasMoreNodes()))
          break label230;
        Node localNode = localSimpleNodeIterator.nextNode();
        StringBuffer localStringBuffer2 = new StringBuffer().append("   ");
        int j = i + 1;
        localStringBuffer1.append(i + " ");
        localStringBuffer1.append(localNode.toString() + "\n");
        i = j;
      }
      localStringBuffer1.append(getAccessKey() + "\n");
    }
    label230: return localStringBuffer1.toString();
  }
}